package com.alphaking.Jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.alphaking.bean.Comments;
import com.alphaking.bean.Reply;
import com.mysql.jdbc.PreparedStatement;

public class JdbcComments {

	private static Connection con = JdbcUtils.getCon();

	public static List<Comments> getComments(int shareid) {

		List<Comments> listComments = new ArrayList<Comments>();

		String sqlSearch = "select * from user_comment where shareid = ?";

		try {
			PreparedStatement pstmt = (PreparedStatement) con.prepareStatement(sqlSearch);

			pstmt.setInt(1, shareid);

			ResultSet rst = pstmt.executeQuery();

			while (rst.next()) {

				Comments comments = new Comments();
				comments.setCommenterAccount(rst.getString("commenter_account"));
				comments.setCommentId(rst.getInt("comment_id"));
				comments.setCommentContent(rst.getString("content"));
				comments.setListReply(JdbcReply.getReplys(rst.getInt("comment_id")));

				listComments.add(comments);

			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return listComments;
	}
}
